var Utils = require('geoUtils');
/**
 * 盯着一个目标
 */
cc.Class({
    extends: cc.Component,

    properties: {
        looker: {
            default: null,
            type: cc.Node,
            tooltip: '观察者',
        },
        lookee: {
            default: null,
            type: cc.Node,
            tooltip: '被观察者',
        },
        delta: {
            default: 0,
            type: cc.Float,
            tooltip: '偏移（用于纠正图像朝向，通常为-90,90,180'
        },
        keepLooking: {
            default: true,
            tooltip: '是否一直盯着'
        },
        lookAtOnLoad: false,
    },
    onLoad(){
        this.looker = this.looker || this.node;
    },

    start() {
        if (this.lookAtOnLoad === true)
            this.lookAt(this.looker, this.lookee, this.keepLooking);
    },

    lookAt(looker, lookee, keepLooking) {
        this.looker = looker || this.looker;
        this.lookee = lookee || this.lookee;
        this.keepLooking = keepLooking;
        //
        if (keepLooking !== true)
            Utils.node.lookAt(this.looker, this.lookee, this.delta);
    },

    stopLookAt() {
        this.keepLooking = false;
    },

    update(dt) {
        if (this.looker && this.lookee && this.keepLooking) {
            Utils.node.lookAt(this.looker, this.lookee, this.delta);
        }
    },
});
